//
//  VCOfFoundPassword.m
//  02_Homework
//
//  Created by 徐昊 on 16/7/16.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "VCOfFoundPassword.h"
#import "ImgTextFieldView.h"

#define WIDTH self.view.frame.size.width
@interface VCOfFoundPassword ()<UITextFieldDelegate>

@end

@implementation VCOfFoundPassword

- (void)viewDidLoad {
    [super viewDidLoad];
    [self config];
    // Do any additional setup after loading the view.
}

- (void)config {
    self.view.backgroundColor = [UIColor whiteColor];
    /** 验证手机 */
    UILabel *confirm = [[UILabel alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - 100) / 2 , 70, 100, 50)];
    confirm.text = @"验证手机";
    confirm.font = [UIFont systemFontOfSize:22];
    confirm.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:confirm];
    /** 输入手机号码 */
    ImgTextFieldView *foundPhoneNumber = [[ImgTextFieldView alloc] initWithFrame:CGRectMake(15, 160, WIDTH - 30, 50) image:[UIImage imageNamed:@"2"] placeHolder:@"(手机号)仅支持中国大陆号"];
    foundPhoneNumber.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:foundPhoneNumber];
    foundPhoneNumber.textField.delegate = self;
    foundPhoneNumber.textField.tag = 3;
    foundPhoneNumber.imageView.tag = 30;
    foundPhoneNumber.textField.backgroundColor = [UIColor whiteColor];
    foundPhoneNumber.imageView.backgroundColor = [UIColor whiteColor];
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:foundPhoneNumber.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = foundPhoneNumber.bounds;
    maskLayer.path = maskPath.CGPath;
    foundPhoneNumber.layer.mask = maskLayer;
    /** 输入验证码 */
    ImgTextFieldView *foundCode = [[ImgTextFieldView alloc] initWithFrame:CGRectMake(15, 222, WIDTH - 30, 50) image:[UIImage imageNamed:@"1"] placeHolder:@"请输入验证码"];
    [self.view addSubview:foundCode];
    foundCode.textField.delegate = self;
    foundCode.textField.tag = 4;
    foundCode.imageView.tag = 40;
    foundCode.backgroundColor = [UIColor whiteColor];
    foundCode.textField.backgroundColor = [UIColor whiteColor];
    foundCode.imageView.backgroundColor = [UIColor whiteColor];
    
    UIBezierPath *codeMaskPath = [UIBezierPath bezierPathWithRoundedRect:foundCode.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerBottomLeft cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *codeMaskLayer = [[CAShapeLayer alloc] init];
    codeMaskLayer.frame = foundCode.bounds;
    codeMaskLayer.path = codeMaskPath.CGPath;
    foundCode.layer.mask = codeMaskLayer;
    
    /** 获取验证码 */
    UIButton *getCode = [UIButton buttonWithType:UIButtonTypeSystem];
    [getCode setTitle:@"获取验证码" forState:UIControlStateNormal];
    getCode.frame = CGRectMake(0, 0, 100, 50);
    getCode.titleLabel.font = [UIFont systemFontOfSize:19];
    [getCode setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [foundCode.textField setRightView:getCode];
    foundCode.textField.rightViewMode = UITextFieldViewModeAlways;
    
    UIButton *next = [UIButton buttonWithType:UIButtonTypeSystem];
    next.frame = CGRectMake( 15, 300, WIDTH - 30, 50);
    next.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    [next setTitle:@"下一步" forState:UIControlStateNormal];
    next.titleLabel.font = [UIFont systemFontOfSize:20];
    [next setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [next addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:next];
    [next.layer setCornerRadius:10.0];
    
    /** 协议文字部分 */
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 350, 158, 30)];
    label.textColor = [UIColor blackColor];
    label.text = @"邮箱用户找回密码,请";
    [self.view addSubview:label];
    
    /** 协议button部分 */
    UIButton *agreement = [UIButton buttonWithType:UIButtonTypeSystem];
    agreement.frame = CGRectMake(155, 350, 110, 30);
    [agreement setTitle:@"点击这里" forState:UIControlStateNormal];
    agreement.titleLabel.textAlignment = NSTextAlignmentLeft;
    agreement.titleLabel.font = [UIFont systemFontOfSize:17.5];
    [agreement setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [self.view addSubview:agreement];
    
    /** 返回button */
    UIButton *returnLastVC = [UIButton buttonWithType:UIButtonTypeSystem];
    returnLastVC.frame = CGRectMake(0, 0, 100, 100);
    [returnLastVC setTitle:@"< 返回" forState:UIControlStateNormal];
    returnLastVC.titleLabel.font = [UIFont systemFontOfSize:22];
    [returnLastVC setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [returnLastVC addTarget:self action:@selector(returnLastVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:returnLastVC];

}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
    if (textField.tag == 3) {
        UIImageView *i = [self.view viewWithTag:30];
        [i setImage:[UIImage imageNamed:@"4"]];
    }
    if (textField.tag == 4) {
        UIImageView *i = [self.view viewWithTag:40];
        [i setImage:[UIImage imageNamed:@"3"]];
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField.tag == 3) {
        UIImageView *i = [self.view viewWithTag:30];
        [i setImage:[UIImage imageNamed:@"2"]];
    }
    if (textField.tag == 4) {
        UIImageView *i = [self.view viewWithTag:40];
        [i setImage:[UIImage imageNamed:@"1"]];
    }
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField endEditing:YES];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)next {
    NSLog(@"你猜的没错, 这个也没实现");
}
- (void)returnLastVC {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
